var t = require("../../utils/config.js");

Page({
    data: {
        imageList: [],
        indicatorDots: !1,
        autoplay: !0,
        interval: 5e3,
        duration: 1e3,
        articleList: [],
        page: 1,
        isEnd: !1,
        unFinishedTaskCount: 0,
        
    },
    onLoad: function(t) {
        this.loadDataSource();
    },
    onReady: function() {},
    onShow: function() {
        var a = this, 
		e = wx.getStorageSync("userId");
        e && wx.request({
            url: t.urlList.API_TASK_GET_UN_FINISHED_TASK_COUNT,
            data: {
                userId: e
            },
            method: "GET",
            success: function(t) {
              //console.log(t.data),
              200 == t.data.status && a.setData({
                    unFinishedTaskCount: t.data.data.count
                });
            }
        });
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {
        this.data.page = 1, this.loadDataSource();
    },
    onReachBottom: function() {
        this.data.isEnd || (this.data.page++, this.loadDataSource());
    },
    onShareAppMessage: function() {},
    loadDataSource: function() {
        var a = this, e = wx.getStorageSync("userId");
        1 == this.data.page && (a.setData({
            isEnd: !1
        }), a.data.articleList = [], wx.request({
           url: t.urlList.API_ARTICLE_GET_BANNER,
           
            data: {
                userId: ""
            },
            header: {
                "content-type": "application/json"
            },
            success: function(t) {
                a.setData({
                    imageList: t.data.data
                });
            }
        })), wx.request({
            url: t.urlList.API_TASK_GET_NEW_TASK_LIST,
            data: {
                page: this.data.page,
                rows: 10,
                userId: e || ""
            },
            header: {
                "content-type": "application/json"
            },
            success: function(t) {
                200 == t.data.status ? a.setData({
                    articleList: a.data.articleList.concat(t.data.data)
                }) : (wx.showToast({
                    title: t.data.message,
                    icon: "none"
                }), a.setData({
                    isEnd: !0
                }), a.data.page--), wx.stopPullDownRefresh();
            }
        });
    },
    goToTaskList: function() {
        wx.navigateTo({
            url: "../task/taskList"
        });
    },
    goToRecruitList: function() {
        wx.navigateTo({
            url: "../task/recruitList"
        });
    },
    goToTaskDetial: function(t) {
        wx.navigateTo({
            url: "../task/taskDetail?id=" + t.currentTarget.dataset.id
        });
    },
    goToTaskManagement: function() {
        wx.getStorageSync("userId") ? wx.navigateTo({
            url: "../task/taskManagement"
        }) : wx.navigateTo({
            url: "../login/login"
        });
    }
});